<div class="mother_root">
<div class="mother_root_child">
<?php
    if(isset($_GET['p']) && $_GET['p'] != ''){
        switch ($_GET['p']) {
            //new menu and admin organizign
            case 'acasa':
                include DIR_A_MODULES . 'rework/pages.php';
                break;
            
            case 'modulePagini':
                include DIR_A_MODULES . 'mods/newPages.php';
                break;
            
            case 'newModInPage':
                include DIR_A_MODULES . 'mods/newAddInPage.php';
                break;
            
            case 'newModInsert':
                $pid = $_POST['pid'];
                $cid = $_POST['cid'];
                $oid = $_POST['oid'];
                $nid = $_POST['nid'];
                $tid = $_POST['tid'];
                $modul = $_POST['modul'];
                $zona = $_POST['zona'];
                $type = $_POST['type'];
                $ordine = $_POST['ordine'];
                $vizibil = $_POST['vizibil'];
                
                mysql_query("insert into dt_mod_visible (`m_id`, `p_id`, `c_id`, `o_id`, `z_id`, `n_id`, `t_id`, `order`, `visible`, `type`) values ('$modul', '$pid', '$cid', '$oid', '$zona', '$nid', '$tid', '$ordine', '$vizibil', '$type')");
                
                if (!empty ($pid))
                    $htmlClass->slc_redirect("index.php?p=modulePagini&pid=$pid");
                elseif (!empty ($cid))
                    $htmlClass->slc_redirect("index.php?p=modulePagini&cid=$cid");
                elseif (!empty ($oid))
                    $htmlClass->slc_redirect("index.php?p=modulePagini&oid=$oid");
                elseif (!empty ($nid))
                    $htmlClass->slc_redirect("index.php?p=modulePagini&nid=$nid");
                elseif (!empty ($tid))
                    $htmlClass->slc_redirect("index.php?p=modulePagini&tid=$tid");
                break;
                
            case 'categ':
                include DIR_A_MODULES . 'rework/categories.php';
                break;
            
            case 'headerPagini':
                include DIR_A_MODULES . 'header/newPages.php';
                break;
            
            case 'newHeadInPage':
                include DIR_A_MODULES . 'header/newAddInPage.php';
                break;
            
            case 'newHeadInsert':
                break;
            
            case 'addNewUser':
                include DIR_A_MODULES . 'users/addNew.php';
                break;
            
            case 'userInsert':
                $username = $_POST['username'];
                $password = md5($_POST['password']);
                $email = $_POST['email'];
                
                mysql_query("insert into dt_users (`username`, `password`, `email`, `active`) values ('$username', '$password', '$email', '1')");
                $htmlClass->slc_redirect('index.php');
                break;
            
            case 'issuu':
                include DIR_A_MODULES . 'issuu/index.php';
                break;
            
            case 'issuuAdd':
                include DIR_A_MODULES . 'issuu/issuuAdd.php';
                break;
            
            case 'issuuInsert':
                $content = $_POST['content'];
                $m_id = $_GET['id'];
                $cid = $_GET['cid'];
                
                mysql_query("insert into dt_issuu (`content`, `m_id`) values ('$content', '$m_id')");
                $htmlClass->slc_redirect("index.php?p=modulePagini&cid=$cid");
                break;
            
            case 'issuuDelete':
                $id = $_GET['id'];
                $m_id = $_GET['m_id'];
                $cid = $_GET['cid'];
                
                mysql_query("delete from dt_issuu where id = '$id'");
                $htmlClass->slc_redirect("index.php?p=issuu&id=$m_id&cid=$cid");
            //end new stuff here
            
            case 'sitemap':
                include DIR_A_MODULES . 'sitemap/index.php';
                break;

            case 'sitemapWrite':
                include DIR_A_MODULES . 'sitemap/create.php';
                $htmlClass->slc_redirect("index.php?p=sitemap");
                break;

            case 'editProfile':
                include DIR_A_MODULES . 'users/index.php';
                break;

            case 'setProfile':
                $id = $_GET['id'];
                $username = $_POST['username'];
                $password = md5($_POST['password']);
                $email = $_POST['email'];
                $active = '1';

                mysql_query("update dt_users set `username` = '$username', `password` = '$password', `email` = '$email', `active` = '$active' where `id` = '$id'");
                break;

            case 'header':
                include DIR_A_MODULES . 'header/index_test.php';
                break;

            case 'hAdd':
                include DIR_A_MODULES . 'header/hAdd.php';
                break;

            case 'hInsert':
                $title = $_POST['title'];
                $subtitle = $_POST['subtitle'];
                $type = $_POST['type'];
                $link = $_POST['link'];
                mysql_query("insert into dt_header (`title`, `subtitle`, `type`, `link`) values ('$title', '$subtitle', '$type', '$link')");
                
                if (isset ($_GET['pid'])) $pid = $_GET['pid']; else $pid = '0';
                if (isset ($_GET['cid'])) $cid = $_GET['cid']; else $cid = '0';
                if (isset ($_GET['oid'])) $oid = $_GET['oid']; else $oid = '0';
                if (isset ($_GET['nid'])) $nid = $_GET['nid']; else $nid = '0';
                if (isset ($_GET['tid'])) $tid = $_GET['tid']; else $tid = '0';
                $insertID = mysql_insert_id();
                mysql_query("insert into dt_header_in_pages (`h_id`, `p_id`, `c_id`, `n_id`, `type`, `order`) values ('$insertID', '$pid', '$cid', '$nid', '$type', '1')");
                $htmlClass->slc_redirect("index.php?p=header");
                break;

            case 'hViewSingle':
                include DIR_A_MODULES . 'header/hUpdate.php';
                break;

            case 'hUpdate':
                $id = $_GET['id'];
                $title = $_POST['title'];
                $subtitle = $_POST['subtitle'];
                $type = $_POST['type'];
                $link = $_POST['link'];
                mysql_query("update dt_header set `title` = '$title', `subtitle` = '$subtitle', `type` = '$type', `link` = '$link' where `id` = '$id'");

                $q1 = mysql_query("select * from dt_header_in_pages where h_id = '$id'");
                while ($q1row = mysql_fetch_array($q1)){
                    mysql_query("update dt_header_in_pages set type = '$type' where h_id = '$id'");
                }

                $htmlClass->slc_redirect("index.php?p=header");
                break;

            case 'hDelete':
                $id = $_GET['id'];

                $q1 = mysql_query("select * from dt_header_content where h_id = '$id'");
                while ($q1row = mysql_fetch_array($q1)){
                    $a = explode("_", $q1row['file']);
                    unlink("../uploads/head_img/thumbs/thumb_".$id."_620-".$a[1]);
                    unlink("../uploads/head_img/thumbs/thumb_".$id."_720-".$a[1]);
                    unlink("../uploads/head_img/thumbs/thumb_".$id."_95-".$a[1]);
                    unlink("../uploads/head_img/".$q1row['file']);
                }
                mysql_query("delete from dt_header_content where h_id = '$id'");
                mysql_query("delete from dt_header_in_pages where h_id = '$id'");

                mysql_query("delete from dt_header where `id` = '$id'");
                $htmlClass->slc_redirect("index.php?p=header");
                break;

            case 'hfp':
                include DIR_A_MODULES . 'header/hfp.php';
                break;

            case 'hfpInsert':
                $h_id = $_GET['h_id'];
                $c_id = $_POST['ctgs'];
                $p_id = $_POST['pgs'];
                $n_id = $_POST['news'];
                $type = $_GET['type'];

                if(isset($_POST['adauga_categorie'])){
                    $order = $_POST['orderCTG'];
                    mysql_query("insert into dt_header_in_pages (`h_id`, `p_id`, `c_id`, `n_id`, `type`, `order`) values ('$h_id', '0', '$c_id', '0', '$type', '$order')");
                }

                if(isset($_POST['adauga_pagina'])){
                    $order = $_POST['orderPGS'];
                    mysql_query("insert into dt_header_in_pages (`h_id`, `p_id`, `c_id`, `n_id`, `type`, `order`) values ('$h_id', '$p_id', '0', '0', '$type', '$order')");
                }

                if (isset($_POST['adauga_stire'])){
                    $order = $_POST['orderNEWS'];
                    mysql_query("insert into dt_header_in_pages (`h_id`, `p_id`, `c_id`, `n_id`, `type`, `order`) values ('$h_id', '0', '0', '$n_id', '$type', '$order')");
                }
                $htmlClass->slc_redirect("index.php?p=hfp&id=".$h_id."&type=".$type);
                break;

            case 'hfpDelete':
                $id = $_GET['id'];
                $h_id = $_GET['h_id'];
                $type = $_GET['type'];
                mysql_query("delete from dt_header_in_pages where id='$id'");
                $htmlClass->slc_redirect("index.php?p=hfp&id=".$h_id."&type=".$type);
                break;

            case 'hfpViewSingle':
                include DIR_A_MODULES . 'header/hfpUpdate.php';
                break;

            case 'hfpUpdate':
                $h_id = $_GET['h_id'];
                $id = $_GET['id'];
                $type = $_GET['type'];
                $order = $_POST['order'];
                mysql_query("update dt_header_in_pages set `order` = '$order' where id = '$id'");
                $htmlClass->slc_redirect("index.php?p=hfp&id=".$h_id."&type=".$type);
                break;

            case 'hContent':
                include DIR_A_MODULES . 'header/hContent.php';
                break;

            case 'hSwfInsert':
                $h_id = $_GET['h_id'];
                $type = $_GET['type'];
                $file = $h_id .'_'. str_replace(" ", "_", $_FILES['photoFile']['name']);
                $picClass->slc_uploadFile("photoFile", $h_id, "../uploads/head_img/");                
                mysql_query("insert into dt_header_content (`file`, `h_id`) values ('$file', '$h_id')");
                $htmlClass->slc_redirect("index.php?p=hContent&id=".$h_id."&type=".$type);
                break;
            
            case 'hImgInsert':
                $h_id = $_GET['h_id'];
                $type = $_GET['type'];

                for($i=1;$i<=5;$i++) {
                    if($_FILES['photoFile'.$i]['name'] != '') {
                        $file = $h_id .'_'. str_replace(" ", "_", $_FILES['photoFile'.$i]['name']);

                        $picClass->slc_uploadFile("photoFile".$i, $h_id, "../uploads/head_img/");
                        $picClass->slc_thumbTest("720", "720");
                        $picClass->slc_thumbTest("620", "620");
                        $picClass->slc_thumbTest("95", "95");

                        mysql_query("insert into dt_header_content (`file`, `h_id`) values ('$file', '$h_id')");
                    }
                }
                $htmlClass->slc_redirect("index.php?p=hContent&id=".$h_id."&type=".$type);
                break;

                case 'hImgDelete':
                    $id = $_GET['id'];
                    $h_id = $_GET['h_id'];
                    $type = $_GET['type'];

                    $data = mysql_query("select * from dt_header_content where id = '$id'");
                    while ($row = mysql_fetch_array($data)){
                        $array = explode("_", $row['file']);

                        unlink("../uploads/head_img/thumbs/thumb_".$array[0]."_620-".$array[1]);
                        unlink("../uploads/head_img/thumbs/thumb_".$array[0]."_720-".$array[1]);
                        unlink("../uploads/head_img/thumbs/thumb_".$array[0]."_95-".$array[1]);
                        unlink("../uploads/head_img/".$row['file']);
                    }

                    mysql_query("delete from dt_header_content where id = '$id'");
                    $htmlClass->slc_redirect("index.php?p=hContent&id=".$h_id."&type=".$_GET['type']);
                    break;

                case 'stirifp':
                    $nrstiri = $_POST['nr_stiri_fp'];
                    mysql_query("update dt_settings set s_nr_items_fp = '$nrstiri'");
                    $htmlClass->slc_redirect("index.php");
                    break;

                case 'pages':
                    include DIR_A_MODULES . 'pages/index.php';
                    break;

                case 'pUpdate':
                    $id = $_GET['id'];
                    $title = $_POST['title'];
                    $content = $_POST['content'];
                    $visible = $_POST['visible'];
                    $meta_desc = $_POST['meta_desc'];
                    $meta_keys = $_POST['meta_keys'];
                    $meta_title = $_POST['meta_title'];

                    $pagesClass->update($id, $title, $content, $visible, $meta_desc, $meta_keys, $meta_title);
                    header("Location: index.php?p=pages");
                    break;

                case 'pDelete':
                    $id = $_GET['id'];
                    $pagesClass->delete($id);
                    header("Location: index.php?p=pages");
                    break;

                case 'pAdd':
                    include DIR_A_MODULES . 'pages/pAdd.php';
                    break;

                case 'pViewSingle':
                    include DIR_A_MODULES . 'pages/pUpdate.php';
                    break;

                case 'pInsert':
                    $title = $_POST['title'];
                    $content = $_POST['content'];
                    $visible = $_POST['visible'];
                    $has_modules = $_POST['has_modules'];
                    $meta_desc = $_POST['meta_desc'];
                    $meta_keys = $_POST['meta_keys'];
                    $meta_title = $_POST['meta_title'];

                    $pagesClass->insert($title, $content, $visible, $has_modules, $meta_desc, $meta_keys, $meta_title);
                    header("Location: index.php?p=pages");
                    break;


                case 'categories':
                    include DIR_A_MODULES . 'categories/index.php';
                    break;

                case 'cUpdate':
                    $id = $_GET['id'];
                    $title = $_POST['title'];
                    $desc = $_POST['desc'];
                    $visible = $_POST['visible'];
                    $meta_desc = $_POST['meta_desc'];
                    $meta_keys = $_POST['meta_keys'];
                    $meta_title = $_POST['meta_title'];

                    if($_GET['pid'] == '')
                        $pid = "0";
                    else
                        $pid = $_GET['pid'];

                    $ctgClass->update($title, $desc, $pid, $visible, $id, $meta_desc, $meta_keys, $meta_title);

                    if($_GET['pid'] != '')
                        header("Location: index.php?p=cSCtg&id=" . $pid);
                    else
                        header("Location: index.php?p=categories");
                    break;

                case 'cDelete':
                    $id = $_GET['id'];

                    //@TODO: add mp3
                    $q1 = mysql_query("select * from dt_offers where c_id = '$id'");
                    while ($q1row = mysql_fetch_array($q1)){
                        $q2 = mysql_query("select * from dt_offers_photos where o_id = '".$q1row['o_id']."'");
                        while ($q2row = mysql_fetch_array($q2)){
                            $picClass->slc_deleteFile("../uploads/offers/img/" . cleanitup($q1row['o_title']) . "/", $q2row['oImg_file']);
                            $picClass->slc_deleteFile("../uploads/offers/img/" . cleanitup($q1row['o_title']) . "/thumbs/thumb_", $q2row['oImg_file']);
                            rmdir("../../uploads/offers/img/".  cleanitup($q1row['o_title']).'/thumbs');
                            rmdir("../../uploads/offers/img/".  cleanitup($q1row['o_title']));
                        }
                        mysql_query("delete from dt_offers_photos where o_id = '".$q1row['o_id']."'");

                        $q3 = mysql_query("select * from dt_offers_video where o_id = '".$q1row['o_id']."'");
                        while ($q3row = mysql_fetch_array($q3)){
                            $picClass->slc_deleteFile("../uploads/offers/video/" . cleanitup($q1row['o_title']) . "/", $q3row['oVid_file']);
                            $picClass->slc_deleteFile("../uploads/offers/video/" . cleanitup($q1row['o_title']) . "/", $q3row['oVid_pic']);
                            rmdir("../../uploads/offers/video/".  cleanitup($q1row['o_title']));
                        }
                        mysql_query("delete from dt_offers_video where o_id = '".$q1row['o_id']."'");
                    }
                    mysql_query("delete from dt_offers where c_id = '$id'");

                    $ctgClass->delete($_GET['id']);
                    header("Location: index.php?p=categories");
                    break;

                case 'cAdd':
                    include DIR_A_MODULES . 'categories/cAdd.php';
                    break;

                case 'cViewSingle':
                    include DIR_A_MODULES . 'categories/cUpdate.php';
                    break;

                case 'cInsert':
                    $title = $_POST['title'];
                    $desc = $_POST['desc'];
                    $visible = $_POST['visible'];
                    $meta_desc = $_POST['meta_desc'];
                    $meta_keys = $_POST['meta_keys'];
                    $meta_title = $_POST['meta_title'];

                    if($_GET['pid'] == '')
                        $pid = "0";
                    else
                        $pid = $_GET['pid'];

                    $ctgClass->insert($title, $desc, $pid, $visible, $meta_desc, $meta_keys, $meta_title);
                    if($_GET['pid'] != '')
                        header("Location: index.php?p=cSCtg&id=" . $pid);
                    else
                        header("Location: index.php?p=categories");
                    break;

                case 'cSCtg':
                    include DIR_A_MODULES . 'categories/cSCtg.php';
                    break;

                case 'cAddSCtg':
                    include DIR_A_MODULES . 'categories/cAddSCtg.php';
                    break;


                case 'newsletter':
                    include DIR_A_MODULES . 'newsletter/index.php';
                    break;

                case 'nlAdd':
                    include DIR_A_MODULES . 'newsletter/uAdd.php';
                    break;

                case 'nlViewSingle':
                    include DIR_A_MODULES . 'newsletter/uUpdate.php';
                    break;

                case 'nlUpdate':
                    $id = $_GET['id'];
                    $email = $_POST['email'];

                    $nlClass->updateUsers($id, $email);
                    header("Location: index.php?p=newsletter");
                    break;

                case 'nlDelete':
                    $id = $_GET['id'];
                    $nlClass->deleteUsers($id);
                    header("Location: index.php?p=newsletter");
                    break;

                case 'nlInsert':
                    $email = $_POST['email'];

                    $nlClass->insertUsers($email);
                    header("Location: index.php?p=newsletter");
                    break;

                case 'nAdd':
                    include DIR_A_MODULES . 'newsletter/nAdd.php';
                    break;

                case 'nViewSingle':
                    include DIR_A_MODULES . 'newsletter/nUpdate.php';
                    break;

                case 'nUpdate':
                    $id = $_GET['id'];
                    $subject = $_POST['subject'];
                    $content = $_POST['content'];

                    $nlClass->update($id, $subject, $content);
                    header("Location: index.php?p=newsletter");
                    break;

                case 'nDelete':
                    $id = $_GET['id'];
                    $nlClass->delete($id);
                    header("Location: index.php?p=newsletter");
                    break;

                case 'nInsert':
                    $subject = $_POST['subject'];
                    $content = $_POST['content'];

                    $nlClass->insert($subject, $content);
                    header("Location: index.php?p=newsletter");
                    break;

                case 'nSend':
                    include DIR_A_MODULES . 'newsletter/nSend.php';
                    header("Location: index.php?p=newsletter");
                    break;


                case 'settings':
                    include DIR_A_MODULES . 'settings/index.php';
                    break;

                case 'sUpdate':
                    $title = $_POST['title'];
                    $meta_desc = $_POST['meta_desc'];
                    $meta_keys = $_POST['meta_keys'];
                    $mail_address = $_POST['mail_address'];
                    $template = $_POST['template'];
                    $iata_link = $_POST['iata_link'];
                    $iata_text = $_POST['iata_text'];
                    $trafic = $_POST['trafic'];

                    $setClass->update($title, $meta_desc, $meta_keys, $mail_address, $template, $iata_link, $iata_text, $trafic);
                    $htmlClass->slc_redirect("index.php?p=settings");
                    break;


                case 'zones':
                    include DIR_A_MODULES . 'zones/index.php';
                    break;

                case 'zAdd':
                    include DIR_A_MODULES . 'zones/zAdd.php';
                    break;

                case 'zInsert':
                    $title = $_POST['title'];
                    $zoneClass->insert($title);
                    $htmlClass->slc_redirect("index.php?p=zones");
                    break;

                case 'zViewSingle':
                    include DIR_A_MODULES . 'zones/zUpdate.php';
                    break;

                case 'zUpdate':
                    $id = $_GET['id'];
                    $title = $_POST['title'];
                    $zoneClass->update($id, $title);
                    $htmlClass->slc_redirect("index.php?p=zones");
                    break;

                case 'zDelete':
                    $id = $_GET['id'];
                    $zoneClass->delete($id);
                    $htmlClass->slc_redirect("index.php?p=zones");
                    break;

                case 'multimedia':
                    include DIR_A_MODULES . 'multimedia/index.php';
                    break;

                case 'mmAdd':
                    $id = $_GET['id'];

                    if($_GET['type'] == 'mmgallery'){
                        for($i=1;$i<=5;$i++){
                            if($_FILES['photoFile'.$i]['name'] != ''){
                                $file = $id . '_' . str_replace(" ", "_", $_FILES['photoFile'.$i]['name']);
                                $picClass->slc_uploadFile("photoFile".$i, $id, "../uploads/multimedia/");
                                $picClass->slc_thumbTest("280", $id);
                                
                                mysql_query("insert into dt_multimedia_content (`path`, `thumb_path`, `m_id`) values ('$file', '', '$id')");
                            }
                        }
                    } else {
                        $file = $id . '_' . str_replace(" ", "_", $_FILES['videoFile']['name']);
                        $thumb = $id . '_' . str_replace(" ", "_", $_FILES['thumbFile']['name']);

                        $picClass->slc_uploadFile("videoFile", $id, "../uploads/multimedia/");
                        $picClass->slc_uploadFile("thumbFile", $id, "../uploads/multimedia/thumbs/");

                        mysql_query("insert into dt_multimedia_content (`path`, `thumb_path`, `m_id`) values ('$file', '$thumb', '$id')");
                    }
                    $htmlClass->slc_redirect("index.php?p=multimedia&type=".$_GET['type']."&id=".$_GET['id']);
                    break;

                case 'mmDelete':
                    $id = $_GET['id'];
                    $mid = $_GET['mid'];
                    $query = mysql_query("select * from dt_multimedia_content where id = '$id'");
                    while($row = mysql_fetch_array($query)){
                        if($_GET['type'] == 'mmgallery'){
                            $array = explode("_", $row['path']);
                            unlink("../uploads/multimedia/thumbs/thumb_".$mid."_".$mid."-".$array[1]);
                            unlink("../uploads/multimedia/".$row['path']);
                        } else {
                            unlink("../uploads/multimedia/thumbs/".$row['thumb_path']);
                            unlink("../uploads/multimedia/".$row['path']);
                        }
                    }

                    mysql_query("delete from dt_multimedia_content where id = '$id'");
                    $htmlClass->slc_redirect("index.php?p=multimedia&type=".$_GET['type']."&id=".$_GET['mid']);
                    break;


                case 'modules':
                    include DIR_A_MODULES . 'mods/index.php';
                    break;

                case 'mAdd':
                    include DIR_A_MODULES . 'mods/mAdd.php';
                    break;

                case 'mInsert':
                    $title = $_POST['title'];
                    $visible = $_POST['visible'];
                    $type = $_POST['type'];

                    $modClass->insert($title, $visible, $type);
                    $htmlClass->slc_redirect("index.php?p=modules");
                    break;

                case 'mViewSingle':
                    include DIR_A_MODULES . 'mods/mUpdate.php';
                    break;

                case 'mUpdate':
                    $id = $_GET['id'];
                    $title = $_POST['title'];
                    $visible = $_POST['visible'];

                    $modClass->update($id, $title, $visible);
                    $htmlClass->slc_redirect("index.php?p=modules");
                    break;

                case 'mDelete':
                    $id = $_GET['id'];

                    mysql_query("delete from dt_mod_visible where m_id = '$id'");

                    $query = mysql_query("select * from dt_modules where m_id = '$id'");
                    while ($row = mysql_fetch_array($query)){
                        if($row[type] == 'top'){
                            $mid = $row['m_id'];
                            $q1 = mysql_query("select * from dt_top where t_id = '$mid'");
                            while ($q1row = mysql_fetch_array($q1)){
                                unlink("../uploads/top_img/thumbs/thumb_".$q1row['top_picture']);
                                unlink("../uploads/top_img/".$q1row['top_picture']);
                            }
                            mysql_query("delete from dt_top where t_id = '$mid'");
                        }
                        if($row['type'] == 'ofertespeciale'){
                            mysql_query("delete from dt_oferte_speciale where m_id = '$mid'");
                        }
                        if($row['type'] == 'mmvideo'){
                            $q2 = mysql_query("select * from dt_multimedia_content where m_id = '$mid'");
                            while ($q2row = mysql_fetch_array($q2)){
                                unlink("../uploads/multimedia/".$q2row['path']);
                                unlink("../uploads/multimedia/thumbs/".$q2row['thumb_path']);
                            }
                            mysql_query("delete from dt_multimedia_content where m_id = '$mid'");
                        }
                        if($row['type'] == 'mmgallery'){
                            $q3 = mysql_query("select * from dt_multimedia_content where m_id = '$mid'");
                            while ($q3row = mysql_fetch_array($q3)){
                                $a = explode("_", $q3row['path']);
                                unlink("../uploads/multimedia/thumbs/thumb_".$q3row['m_id'].'_'.$q3row['m_id'].'-'.$a[1]);
                                unlink("../uploads/multimedia/".$q3row['path']);
                            }
                            mysql_query("delete from dt_multimedia_content where m_id = '$mid'");
                        }
                    }

                    $modClass->delete($id);
                    header("Location: index.php?p=modules");
                    break;

                case 'mfp':
                    include DIR_A_MODULES . 'mods/mForPages.php';
                    break;

                case 'mfpAdd':
                    include DIR_A_MODULES . 'mods/mfpAdd.php';
                    break;

                case 'mfpInsert':
                    $m_id = $_GET['m_id'];
                    $c_id = $_POST['ctgs'];
                    $p_id = $_POST['pgs'];
                    $o_id = $_POST['offs'];
                    $n_id = $_POST['news'];
                    $t_id = $_POST['top'];
                    $type = $_GET['type'];

                    if(isset($_POST['adauga_categorie'])){
                        $z_id = $_POST['zonesCTG'];
                        $order = $_POST['orderCTG'];
                        $visible = $_POST['visibleCTG'];
                        $modClass->mfpInsert($m_id, '0', $c_id, '0', $z_id, '0', '0', $order, $visible, $type);
                    }

                    if(isset($_POST['adauga_pagina'])){
                        $z_id = $_POST['zonesPGS'];
                        $order = $_POST['orderPGS'];
                        $visible = $_POST['visiblePGS'];
                        $modClass->mfpInsert($m_id, $p_id, '0', '0', $z_id, '0', '0', $order, $visible, $type);
                    }

                    if(isset($_POST['adauga_oferta'])){
                        $z_id = $_POST['zonesOFF'];
                        $order = $_POST['orderOFF'];
                        $visible = $_POST['visibleOFF'];
                        $modClass->mfpInsert($m_id, '0', '0', $o_id, $z_id, '0', '0', $order, $visible, $type);
                    }

                    if (isset($_POST['adauga_stire'])){
                        $z_id = $_POST['zonesNEWS'];
                        $order = $_POST['orderNEWS'];
                        $visible = $_POST['visibleNEWS'];
                        $modClass->mfpInsert($m_id, '0', '0', '0', $z_id, $n_id, '0', $order, $visible, $type);
                    }

                    if (isset($_POST['adauga_top'])){
                        $z_id = $_POST['zonesTOP'];
                        $order = $_POST['orderTOP'];
                        $visible = $_POST['visibleTOP'];
                        $modClass->mfpInsert($m_id, '0', '0', '0', $z_id, '0', $t_id, $order, $visible, $type);
                    }

                    $htmlClass->slc_redirect("index.php?p=mfp&id=".$m_id.'&type='.$type);
                    break;

                case 'mfpViewSingle':
                    include DIR_A_MODULES . 'mods/mfpUpdate.php';
                    break;

                case 'mfpUpdate':
                    $m_id = $_GET['m_id'];
                    $id = $_GET['id'];
                    $z_id = $_POST['zones'];
                    $order = $_POST['order'];
                    $visible = $_POST['visible'];

                    $modClass->mfpUpdate($id, $z_id, $order, $visible);
                    $htmlClass->slc_redirect("index.php?p=mfp&id=".$m_id);
                    break;

                case 'mfpDelete':
                    $id = $_GET['id'];
                    $m_id = $_GET['m_id'];
                    $modClass->mfpDelete($id);
                    $htmlClass->slc_redirect("index.php?p=mfp&id=".$m_id);
                    break;


                case 'news':
                    include DIR_A_MODULES . 'news/index.php';
                    break;

                case 'newsAdd':
                    include DIR_A_MODULES . 'news/newsAdd.php';
                    break;

                case 'newsInsert':
                    $title = $_POST['title'];
                    $content = $_POST['content'];
                    $visible = $_POST['visible'];
                    $meta_title = $_POST['meta_title'];
                    $meta_desc = $_POST['meta_desc'];
                    $meta_keys = $_POST['meta_keys'];
                    $date = $_POST['date'];

                    $newsClass->insert($title, $content, $visible, $meta_title, $meta_desc, $meta_keys, $date);
                    $htmlClass->slc_redirect("index.php?p=news");
                    break;

                case 'newsViewSingle':
                    include DIR_A_MODULES . 'news/newsUpdate.php';
                    break;

                case 'newsUpdate':
                    $id = $_GET['id'];
                    $title = $_POST['title'];
                    $content = $_POST['content'];
                    $visible = $_POST['visible'];
                    $meta_title = $_POST['meta_title'];
                    $meta_desc = $_POST['meta_desc'];
                    $meta_keys = $_POST['meta_keys'];

                    $newsClass->update($id, $title, $content, $visible, $meta_title, $meta_desc, $meta_keys);
                    $htmlClass->slc_redirect("index.php?p=news");
                    break;

                case 'newsDelete':
                    $id = $_GET['id'];
                    $newsClass->delete($id);
                    $htmlClass->slc_redirect("index.php?p=news");
                    break;


                case 'top':
                    include DIR_A_MODULES . 'top/index.php';
                    break;

                case 'adaugaTop':
                    include DIR_A_MODULES . 'top/adaugaTop.php';
                    break;

                case 'topNou':
                    $title = $_POST['title'];
                    $visible = $_POST['visible'];

                    mysql_query("insert into dt_top_visible (`title`, `visible`) values ('$title', '$visible')");
                    $htmlClass->slc_redirect("index.php?p=topuri");
                    break;

                case 'topuri':
                    include DIR_A_MODULES . 'top/topuri.php';
                    break;

                case 'topsingur':
                    include DIR_A_MODULES . 'top/topsingur.php';
                    break;

                case 'topschimba':
                    $id = $_GET['id'];
                    $title = $_POST['title'];
                    $visible = $_POST['visible'];

                    mysql_query("update dt_top_visible set `title` = '$title', `visible` = '$visible' where `id` = '$id'");
                    $htmlClass->slc_redirect("index.php?p=topuri");
                    break;

                case 'topsterge':
                    $id = $_GET['id'];
                    mysql_query("delete from dt_top_visible where `id` = '$id'");
                    $htmlClass->slc_redirect("index.php?p=topuri");
                    break;

                case 'topAdd':
                        include DIR_A_MODULES . 'top/topAdd.php';
                        break;

                case 'topInsert':
                    $title = $_POST['title'];
                    $content = $_POST['content'];
                    $picture = cleanitup($title) .'_'. str_replace(" ", "_", $_FILES['picture']['name']);
                    $visible = $_POST['visible'];
                    $meta_title = $_POST['meta_title'];
                    $meta_desc = $_POST['meta_desc'];
                    $meta_keys = $_POST['meta_keys'];
                    $id = $_GET['tid'];

                    if ($_FILES['picture']['name'] != ''){
                        mysql_query("insert into dt_top (`top_title`, `top_content`, `top_picture`, `top_visible`, `meta_title`, `meta_description`, `meta_keys`, `t_id`) values ('$title', '$content', '$picture', '$visible', '$meta_title', '$meta_desc', '$meta_keys', '$id')");
                        $picClass->slc_uploadFile("picture", cleanitup($title), "../uploads/top_img/");
                        $picClass->slc_createThumb("90");
                    } else {
                        mysql_query("insert into dt_top (`top_title`, `top_content`, `top_picture`, `top_visible`, `meta_title`, `meta_description`, `meta_keys`, `t_id`) values ('$title', '$content', '', '$visible', '$meta_title', '$meta_desc', '$meta_keys', '$id')");
                    }

                    $htmlClass->slc_redirect("index.php?p=top");
                    break;

                case 'topViewSingle':
                        include DIR_A_MODULES . 'top/topUpdate.php';
                        break;

                case 'topUpdate':
                    $id = $_GET['id'];
                    $title = $_POST['title'];
                    $content = $_POST['content'];
                    $picture = cleanitup($title) .'_'. str_replace(" ", "_", $_FILES['picture']['name']);
                    $visible = $_POST['visible'];
                    $t_id = $_POST['t_id'];

                    $topItems = $topClass->selectSingle($id);
                    $item = mysql_fetch_array($topItems);

                    if($_FILES['picture']['name'] != '')
                            $picClass->slc_deleteFile("../uploads/top_img/", $item['top_picture']);

                    $picClass->slc_uploadFile("picture", cleanitup($title), "../uploads/top_img/");
                    $picClass->slc_createThumb("250");

                    if($_FILES['picture']['name'] != '')
                            $topClass->update($id, $title, $content, $picture, $visible, $t_id);
                    else
                            $topClass->updateNOPic($id, $title, $content, $visible, $t_id);

                    $htmlClass->slc_redirect("index.php?p=top");
                    break;

                case 'topDelete':
                    $id = $_GET['id'];
                    $topItems = $topClass->selectSingle($id);
                    $item = mysql_fetch_array($topItems);
                    $picClass->slc_deleteFile("../uploads/top_img/", $item['top_picture']);
                    $topClass->delete($id);
                    $htmlClass->slc_redirect("index.php?p=top");
                    break;


                case 'offers':
                    include DIR_A_MODULES . 'offers/index.php';
                    break;

                case 'oHeadChange':
                    $id = $_GET['id'];
                    $type = $_POST['type'];

                    mysql_query("update dt_offers set head_type = '$type' where o_id = '$id'");
                    $htmlClass->slc_redirect("index.php?p=offers");
                    break;

                case 'oActiveChange':
                    $id = $_GET['id'];
                    $active = $_POST['active'];

                    mysql_query("update dt_offers set o_active = '$active' where o_id = '$id'");
                    $htmlClass->slc_redirect("index.php?p=offers");
                    break;

                case 'oAdd':
                    include DIR_A_MODULES . 'offers/oAdd.php';
                    break;

                case 'oInsert':
                    $label = $_POST['label'];
                    $title = $_POST['title'];
                    $price = $_POST['price'];
                    $price_type = $_POST['price_type'];
                    $content = $_POST['content'];
                    $housing = $_POST['housing'];
                    $housing_link = $_POST['housing_link'];
                    $start_date = $_POST['start_date'];
                    $end_date = $_POST['end_date'];
                    $special = '0';
                    $active = $_POST['active'];
                    $meta_title = $_POST['meta_title'];
                    $meta_desc = $_POST['meta_desc'];
                    $meta_keys = $_POST['meta_keys'];
                    $mese_incluse = $_POST['mese_incluse'];
                    $orase_vizitate = $_POST['orase_vizitate'];
                    $excursii_optionale = $_POST['excursii_optionale'];
                    $random = '0';
                    $latitudine = $_POST['latitudine'];
                    $longitudine = $_POST['longitudine'];
                    
                    //new
                    $o_small_desc = $_POST['small_desc'];
                    $category = $_GET['cid'];
                    $head_type = "gallery";

                    mkdir(DIR_ROOT . "uploads/offers/video/" . cleanitup($title));
                    mkdir(DIR_ROOT . "uploads/offers/img/" . cleanitup($title));
                    mkdir(DIR_ROOT . "uploads/offers/img/" . cleanitup($title) . "/thumbs");
                    mkdir(DIR_ROOT . "uploads/offers/mp3/" . cleanitup($title));

                    $offersClass->insert($label, $title, $price, $price_type, $content, $housing, $housing_link, $start_date, $end_date, $special, $active, $random, $meta_title, $meta_desc, $meta_keys, $category, $mese_incluse, $orase_vizitate, $excursii_optionale, $latitudine, $longitudine, $head_type, $o_small_desc);
                    
                    $id = mysql_insert_id();
                    
                    $htmlClass->slc_redirect("index.php?p=oPhotos&id=$id&cid=$category");
                    break;

                case 'oViewSingle':
                    include DIR_A_MODULES . 'offers/oUpdate.php';
                    break;

                case 'oUpdate':
                    $id = $_GET['id'];
                    $label = $_POST['label'];
                    $title = $_POST['title'];
                    $price = $_POST['price'];
                    $price_type = $_POST['price_type'];
                    $content = $_POST['content'];
                    $housing = $_POST['housing'];
                    $housing_link = $_POST['housing_link'];
                    $start_date = $_POST['start_date'];
                    $end_date = $_POST['end_date'];

                    if (isset($_POST['special'])) $special = $_POST['special'];
                    
                    $active = $_POST['active'];
                    $random = $_POST['random'];
                    $meta_title = $_POST['meta_title'];
                    $meta_desc = $_POST['meta_desc'];
                    $meta_keys = $_POST['meta_keys'];
                    $mese_incluse = $_POST['mese_incluse'];
                    $orase_vizitate = $_POST['orase_vizitate'];
                    $excursii_optionale = $_POST['excursii_optionale'];
                    $latitudine = $_POST['latitudine'];
                    $longitudine = $_POST['longitudine'];
                    
                    //new
                    $head_type = "gallery"; //@TODO: needs fix (can't always be gallery)
                    $o_small_desc = $_POST['small_desc'];
                    $category = $_GET['cid'];

                    //new modules
                    $ctg_os = $_POST['ctg_os'];

                    if($ctg_os != '' && $special != ''){
                        $query = mysql_query("select * from dt_oferte_speciale where o_id = '$id'");
                        while($qRow = mysql_fetch_array($query)){
                            mysql_query("delete from dt_oferte_speciale where o_id = '$id'");
                        }
                        mysql_query("insert into dt_oferte_speciale (`m_id`, `o_id`) values ('$ctg_os', '$id')");
                    }
                    //end new modules

                    $oldname = $_POST['oldname'];

                    rename(DIR_ROOT . "uploads/offers/video/" . cleanitup($oldname), DIR_ROOT . "uploads/offers/video/" . cleanitup($title));
                    rename(DIR_ROOT . "uploads/offers/img/" . cleanitup($oldname), DIR_ROOT . "uploads/offers/img/" . cleanitup($title));

                    if($category != '2' && $category != '3')
                        $offersClass->update($id, $label, $title, $price, $price_type, $content, $housing, $housing_link, $start_date, $end_date, '0', $active, $random, $meta_title, $meta_desc, $meta_keys, $category, $mese_incluse, $orase_vizitate, $excursii_optionale, $latitudine, $longitudine, $head_type, $o_small_desc);
                    elseif($category == '2')
                        $offersClass->update($id, $label, $title, $price, $price_type, $content, $housing, $housing_link, $start_date, $end_date, '0', $active, '0', $meta_title, $meta_desc, $meta_keys, $category, $mese_incluse, $orase_vizitate, $excursii_optionale, $latitudine, $longitudine, $head_type, $o_small_desc);
                    elseif($category == '3')
                        $offersClass->update($id, $label, $title, $price, $price_type, $content, $housing, $housing_link, $start_date, $end_date, $special, $active, $random, $meta_title, $meta_desc, $meta_keys, $category, $mese_incluse, $orase_vizitate, $excursii_optionale, $latitudine, $longitudine, $head_type, $o_small_desc);
                    $htmlClass->slc_redirect("index.php?p=categ&cid=$category");
                    break;

                case 'oDelete':
                    $id = $_GET['id'];
                    $category = $_GET['cid'];

                    $q1 = mysql_query("select * from dt_offers where o_id = '$id'");
                    while ($q1row = mysql_fetch_array($q1)){
                        $q2 = mysql_query("select * from dt_offers_photos where o_id = '".$q1row['o_id']."'");
                        while ($q2row = mysql_fetch_array($q2)){
                            $picClass->slc_deleteFile("../uploads/offers/img/" . cleanitup($q1row['o_title']) . "/", $q2row['oImg_file']);
                            $picClass->slc_deleteFile("../uploads/offers/img/" . cleanitup($q1row['o_title']) . "/thumbs/thumb_", $q2row['oImg_file']);
                            rmdir("../../uploads/offers/img/".  cleanitup($q1row['o_title']).'/thumbs');
                            rmdir("../../uploads/offers/img/".  cleanitup($q1row['o_title']));
                        }
                        mysql_query("delete from dt_offers_photos where o_id = '".$q1row['o_id']."'");

                        $q3 = mysql_query("select * from dt_offers_video where o_id = '".$q1row['o_id']."'");
                        while ($q3row = mysql_fetch_array($q3)){
                            $picClass->slc_deleteFile("../uploads/offers/video/" . cleanitup($q1row['o_title']) . "/", $q3row['oVid_file']);
                            $picClass->slc_deleteFile("../uploads/offers/video/" . cleanitup($q1row['o_title']) . "/", $q3row['oVid_pic']);
                            rmdir("../../uploads/offers/video/".  cleanitup($q1row['o_title']));
                        }
                        mysql_query("delete from dt_offers_video where o_id = '".$q1row['o_id']."'");
                    }

                    $offersClass->delete($id);
                    $htmlClass->slc_redirect("index.php?p=categ&cid=$category");
                    break;

                case 'oPhotos':
                    include DIR_A_MODULES . 'offers/oPhotos.php';
                    break;

                case 'oImgInsert':
                    $oid = $_GET['oid'];
                    $title = $_POST['folder'];

                    for($i=1;$i<=5;$i++) {
                        if($_FILES['photoFile'.$i]['name'] != '') {
                            $file = str_replace(" ", "_", $_FILES['photoFile'.$i]['name']);

                            $picClass->slc_uploadFile("photoFile".$i, '', "../uploads/offers/img/" . cleanitup($title) . '/');
                            $picClass->slc_createThumb("160");
                            $offersClass->picInsert($file, $oid);
                        }
                    }
                    $htmlClass->slc_redirect("index.php?p=offers");
                    break;

                case 'oImgDelete':
                    $id = $_GET['id'];
                    $oid = $_GET['oid'];

                    $pics = $offersClass->picSelectSingle($id);
                    $pic = mysql_fetch_array($pics);

                    $offers = $offersClass->selectSingle($oid);
                    $offer = mysql_fetch_array($offers);

                    $picClass->slc_deleteFile("../uploads/offers/img/" . cleanitup($offer['o_title']) . "/", $pic['oImg_file']);
                    $picClass->slc_deleteFile("../uploads/offers/img/" . cleanitup($offer['o_title']) . "/thumbs/thumb_", $pic['oImg_file']);

                    $offersClass->picDelete($id);
                    $htmlClass->slc_redirect("index.php?p=offers");
                    break;

                case 'oVideo':
                    include DIR_A_MODULES . 'offers/oVideo.php';
                    break;

                case 'oVideoInsert':
                    $oid = $_GET['oid'];
                    $title = $_POST['folder'];
                    $thumbnail = $_FILES['thumbFile']['name'];

                    //removed support for multi upload
                    if($_FILES['videoFile']['name'] != '') {
                        $file = str_replace(" ", "_", $_FILES['videoFile']['name']);
                        $thumb = $oid . '_' . str_replace(" ", "_", $thumbnail);

                        $picClass->slc_uploadFile("videoFile", '', "../uploads/offers/video/" . cleanitup($title) . '/');
                        $picClass->slc_uploadFile("thumbFile", $oid, "../uploads/offers/video/".cleanitup($title).'/');
                        $offersClass->vidInsert($file, $thumb, $oid);
                    }
                    $htmlClass->slc_redirect("index.php?p=offers");
                    break;

                case 'oVideoDelete':
                    $id = $_GET['id'];
                    $oid = $_GET['oid'];

                    $vids = $offersClass->vidSelectSingle($id);
                    $vid = mysql_fetch_array($vids);

                    $offers = $offersClass->selectSingle($oid);
                    $offer = mysql_fetch_array($offers);

                    $picClass->slc_deleteFile("../uploads/offers/video/" . cleanitup($offer['o_title']) . "/", $vid['oVid_file']);
                    $picClass->slc_deleteFile("../uploads/offers/video/" . cleanitup($offer['o_title']) . "/", $vid['oVid_pic']);

                    $offersClass->vidDelete($id);
                    $htmlClass->slc_redirect("index.php?p=offers");
                    break;

                case 'oAudio':
                    include DIR_A_MODULES . 'offers/oAudio.php';
                    break;

                case 'oAudioInsert':
                    $oid = $_GET['oid'];
                    $title = $_POST['folder'];

                    //removed support for multi upload
                    if($_FILES['videoFile']['name'] != '') {
                        $file = $oid . "_" .str_replace(" ", "_", $_FILES['videoFile']['name']);

                        $picClass->slc_uploadFile("videoFile", $oid, "../uploads/offers/mp3/" . cleanitup($title) . '/');
                        $offersClass->mp3Insert($file, $oid);

                        $folderQ = mysql_query("select * from dt_offers where o_id = '$oid'");
                        $folderR = mysql_fetch_array($folderQ);

                        $fileXML = fopen('../uploads/offers/mp3/'.cleanitup($folderR['o_title']).'/'.substr($file, 0, -4).'.xml', "w");
                        $fileString = '<?xml version="1.0" encoding="utf-8"?>
                                        <playlist>
                                            <folder name="'.cleanitup($folderR['o_title']).'">
                                                <file path="'.$file.'" artistName="Artist" songName = "Melodie" />
                                            </folder>
                                        </playlist>';
                        fwrite($fileXML, $fileString);
                        fclose($fileXML);
                    }
                    $htmlClass->slc_redirect("index.php?p=offers");
                    break;

                case 'oAudioDelete':
                    $id = $_GET['id'];
                    $oid = $_GET['oid'];

                    $vids = $offersClass->mp3SelectSingle($id);
                    $vid = mysql_fetch_array($vids);

                    $offers = $offersClass->selectSingle($oid);
                    $offer = mysql_fetch_array($offers);

                    $picClass->slc_deleteFile("../uploads/offers/mp3/" . cleanitup($offer['o_title']) . "/", $vid['file']);
                    $picClass->slc_deleteFile("../uploads/offers/mp3/" . cleanitup($offer['o_title']) . "/", substr($vid['file'],0,-4).'.xml');

                    $offersClass->mp3Delete($id);
                    $htmlClass->slc_redirect("index.php?p=offers");
                    break;

                case 'fileManager':
                    include DIR_A_MODULES . 'filemanager/index.php';
                    break;


                case 'pdf':
                    include DIR_A_MODULES . 'pdf/index.php';
                    break;

                case 'pdfAdd':
                    include DIR_A_MODULES . 'pdf/pdfAdd.php';
                    break;

                case 'pdfInsert':
                    $title = $_POST['title'];
                    $content = $_POST['content'];
                    $link = cleanitup($title) .'_'. str_replace(" ", "_", $_FILES['file']['name']);
                    $visible = $_POST['visible'];

                    $picClass->slc_uploadFile("file", cleanitup($title), "../uploads/pdf_files/");

                    $pdfClass->insert($title, $content, $link, $visible);
                    $htmlClass->slc_redirect("index.php?p=pdf");
                    break;

                case 'pdfViewSingle':
                    include DIR_A_MODULES . 'pdf/pdfUpdate.php';
                    break;

                case 'pdfUpdate':
                    $id = $_GET['id'];
                    $title = $_POST['title'];
                    $content = $_POST['content'];
                    $link = cleanitup($title) .'_'. str_replace(" ", "_", $_FILES['file']['name']);
                    $visible = $_POST['visible'];

                    $pdfFiles = $pdfClass->selectSingle($id);
                    $pdfFile = mysql_fetch_array($pdfFiles);

                    if($_FILES['file']['name'] != '')
                            $picClass->slc_deleteFile("../uploads/pdf_files/", $pdfFile['pdf_link']);

                    $picClass->slc_uploadFile("file", cleanitup($title), "../uploads/pdf_files/");

                    if($_FILES['picture']['name'] != '')
                            $pdfClass->update($id, $title, $content, $link, $visible);
                    else
                            $pdfClass->updateNOFile($id, $title, $content, $visible);

                    $htmlClass->slc_redirect("index.php?p=pdf");
                    break;

                case 'pdfDelete':
                    $id = $_GET['id'];

                    $pdfFiles = $pdfClass->selectSingle($id);
                    $pdfFile = mysql_fetch_array($pdfFiles);
                    $picClass->slc_deleteFile("../uploads/pdf_files/", $pdfFile['pdf_link']);

                    $pdfClass->delete($id);

                    $htmlClass->slc_redirect("index.php?p=pdf");
                    break;
            }
    } else {
            include DIR_A_MODULES . 'main/index.php';
    }
?>